<template>
	<view class="phone">
		<navbar></navbar>
		<textNavbar myprops="手机号"></textNavbar>
		<view class="phone-vw">
			<text>更换手机后，下次登录可使用新的手机号登录。当前手机号：15879779339</text>
		</view>
		<view>
			<van-cell-group>
			  <van-field
			    :value="value"
			    center
			    clearable
			    label="手机号"
			    placeholder="请输入手机号"
			    use-button-slot
					@input="input1"
			  >
			    <van-button @click="yzmHadnler" slot="button" size="small" type="default" custom-style="border: none; color: #6e7589;">
			      发送验证码
			    </van-button>
			  </van-field>
				<van-field
				    :value="verifyPeople"
						label="验证码"
				    placeholder="请输入验证码"
						@input="input2"
				  />
			</van-cell-group>
		</view>
		<view class="content-btn">
			<van-button type="info" round block custom-style="font-size: 36rpx; background: #036faf;" @click="changephone">提交</van-button>
		</view>
		<van-toast id="van-toast" />
	</view>
</template>

<script>
	import { token, serverURL } from '../../../services/httpService';
	import Toast from '@vant/weapp/dist/toast/toast';
	export default {
		data() {
			return {
				value: '',
				verifyPeople: '',
			}
		},
		methods: {
			// 发送验证码逻辑
			yzmHadnler () {
				uni.request({
					url: `${serverURL}/api/getCode`,
					method: "POST",
					header: {
						Authorizationpas: `Bearer ${token}`,
					},
					data: {
						phone: this.value
					},
					success(res) {
						console.log('成功',res.data);
						if(res.data.status == 200) {
							Toast('发送成功')
						}
					},
				})
			},
			// 提交的逻辑
			changephone () {
				console.log(this.value);
				console.log(this.verifyPeople);
				uni.request({
					url: `${serverURL}/api/bindPhone`,
					method: "POST",
					header: {
						Authorizationpas: `Bearer ${token}`,
					},
					data: {
						phone: this.value,
						code: this.verifyPeople
					},
					success(res) {
						console.log('成功',res.data);
					},
				})
			},
			input1 (event) {
				this.value = event.detail
			},
			input2 (event) {
				this.verifyPeople = event.detail
			}
		}
	}
</script>

<style lang="scss" scoped>
	.phone {
		height: 100vh;
		width: 100vw;
		background-color: #EDEDED;
	}
	.phone-vw {
		width: 92vw;
		font-size: 24rpx;
		margin: 0 auto;
		color: #878787;
	}
	.content-btn {
		width: 690rpx;
		height: 88rpx;
		margin: 40rpx auto;
	}
</style>
